<!DOCTYPE html>
<html>
<head>
  <title>p-V Diagram</title>
</head>
<body>
  <canvas id="thermo-diagram" width="500" height="500" style="border:1px solid #000;"></canvas>
  <script>
    const canvas = document.getElementById('thermo-diagram');
    const ctx = canvas.getContext('2d');

    // Define coordinate system parameters
    const originX = 60;
    const originY = 440;
    const axisEndX = 460;
    const axisEndY = 40;

    // Define the points of the rectangle in logical coordinates
    // These values are chosen to create a visually similar rectangle to the source image
    const v_a = 80;
    const p_a = 80;
    const v_b = 360;
    const p_b = 320;

    // Convert logical coordinates to canvas coordinates
    // (0,0) is at top-left, y increases downwards
    const a = { x: originX + v_a, y: originY - p_a };
    const b = { x: originX + v_b, y: originY - p_b };
    const c = { x: originX + v_a, y: originY - p_b };
    const d = { x: originX + v_b, y: originY - p_a };

    // Set common styles
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.font = 'italic 20px Times New Roman';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // --- Draw Axes ---
    ctx.lineWidth = 2;
    // p-axis (vertical)
    ctx.beginPath();
    ctx.moveTo(originX, originY);
    ctx.lineTo(originX, axisEndY);
    // Arrowhead
    ctx.moveTo(originX, axisEndY);
    ctx.lineTo(originX - 6, axisEndY + 15);
    ctx.moveTo(originX, axisEndY);
    ctx.lineTo(originX + 6, axisEndY + 15);
    ctx.stroke();
    ctx.fillText('p', originX, axisEndY - 15);

    // V-axis (horizontal)
    ctx.beginPath();
    ctx.moveTo(originX, originY);
    ctx.lineTo(axisEndX, originY);
    // Arrowhead
    ctx.moveTo(axisEndX, originY);
    ctx.lineTo(axisEndX - 15, originY - 6);
    ctx.moveTo(axisEndX, originY);
    ctx.lineTo(axisEndX - 15, originY + 6);
    ctx.stroke();
    ctx.fillText('V', axisEndX + 15, originY);

    // Origin label
    ctx.fillText('O', originX - 20, originY + 20);

    // --- Draw Rectangle a-c-b-d ---
    ctx.lineWidth = 1.5;
    ctx.beginPath();
    ctx.moveTo(a.x, a.y);
    ctx.lineTo(c.x, c.y);
    ctx.lineTo(b.x, b.y);
    ctx.lineTo(d.x, d.y);
    ctx.closePath();
    ctx.stroke();

    // --- Draw Curved Path a-b ---
    ctx.lineWidth = 3;
    ctx.beginPath();
    ctx.moveTo(a.x, a.y);
    // A quadratic Bezier curve with the control point at 'd' gives a shape
    // that is tangent to the horizontal line at 'a' and the vertical line at 'b',
    // closely resembling the convex curve in the diagram.
    ctx.quadraticCurveTo(d.x, d.y, b.x, b.y);
    ctx.stroke();

    // --- Draw Labels for Points ---
    ctx.fillText('a', a.x - 15, a.y + 15);
    ctx.fillText('b', b.x + 15, b.y - 10);
    ctx.fillText('c', c.x - 15, c.y - 10);
    ctx.fillText('d', d.x + 15, d.y + 15);

  </script>
</body>
</html>